package com.jwdf.uda.ui.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.text.TextUtils;
import android.view.View;
import com.jwdf.uda.R;
import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.databinding.IncludeCommentUserInfoBinding;
import com.jwdf.uda.databinding.ItemCommentTxtBinding;
import com.jwdf.uda.event.GuideDetailItemClickEvent;
import com.jwdf.uda.ui.activity.UserInfoActivity;
import com.jwdf.uda.ui.adapter.AbsViewHolder;
import com.jwdf.uda.ui.adapter.item.GuideDetailItem;
import com.jwdf.uda.utils.DateUtils;
import com.jwdf.uda.utils.EventBusUtil;
import com.jwdf.uda.utils.StringUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * 类说明：
 */
public class GuideInteractionTxtViewHolder extends AbsViewHolder<GuideDetailItem> {
    private ItemCommentTxtBinding mItemBinding;

    public GuideInteractionTxtViewHolder(View convertView) {
        super(convertView);
        mItemBinding = DataBindingUtil.bind(convertView);
        convertView.setOnClickListener(this);
        mItemBinding.topLayout.llHeadLayout.setOnClickListener(this);
    }

    @Override
    protected void onBindView(GuideDetailItem item) {
        PbBean.PbGuideInteraction interaction = item.interaction;
        if (interaction == null) return;
        mItemBinding.tvTime.setVisibility(View.VISIBLE);
        mItemBinding.tvTime.setText(DateUtils.getFriendlyTime(interaction.getCreateTime()));
        onBindCommonView(mItemBinding.topLayout, interaction);
    }

    static void onBindCommonView(IncludeCommentUserInfoBinding topLayout, PbBean.PbGuideInteraction item) {
        topLayout.tvName.setText(item.getUserInfo().getNickname());
        topLayout.tvContent.setVisibility(TextUtils.isEmpty(item.getContent()) ? View.GONE : View.VISIBLE);
        topLayout.tvContent.setText(item.getContent());
        topLayout.ivIsDesigner.setVisibility(item.getUserInfo().getIsDesigner() ? View.VISIBLE : View.GONE);
        topLayout.tvDate.setVisibility(TextUtils.isEmpty(StringUtils.filterNullAndTrim(item.getUserInfo().getIntroduction())) ? View.GONE : View.VISIBLE);
        topLayout.tvDate.setText(item.getUserInfo().getIntroduction());
        ImageLoader.getInstance().displayImage(item.getUserInfo().getAvatar().getUrl(), topLayout.ivHeader);

    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.ll_head_layout) {
            if (item.interaction != null) {
                UserInfoActivity.start(v.getContext(), item.interaction.getUserInfo().getUserId(), item.interaction.getUserInfo().getIsDesigner());
            }
            return;
        }
        EventBusUtil.post(new GuideDetailItemClickEvent(item));
    }
}
